﻿using MediatR;
using SheepCultivation.Common.Domain.PurchaseSales;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;

namespace SheepCultivation.API.AddliCation.PurchaseSales
{
    public class BuyerSeachHandler : IRequestHandler<BuyerSeachCommon, Result>
    {
        public readonly IBaseRepository<Buyer> BuyerRepository;
        public BuyerSeachHandler(IBaseRepository<Buyer> buyerRepository)
        {
            BuyerRepository = buyerRepository;
        }

        public async Task<Result> Handle(BuyerSeachCommon request, CancellationToken cancellationToken)
        {
            var res = new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                var list = BuyerRepository.GetAll().ToList();
                res.Code = (int)CommonEnumCode.success;
                res.Data = list;
                res.Msg = "采购员显示";
            }
            catch (Exception)
            {

                throw;
            }
            return res;
        }
    }
}
